package SleepAndWait;

import java.util.stream.Stream;

/**
 * @author Kevin
 * @date 2020/3/5 2:14
 * 参考https://baijiahao.baidu.com/s?id=1647423693517849309&wfr=spider&for=pc
 */
public class TestSleep {
    private final static Object lock = new Object();
    public static void main(String[] args) {
        Stream.of("线程1", "线程2").forEach(n ->new Thread(n) {
            public void run() {
                TestSleep.testSleep();
            }
        }.start());
    }
    //Sleep方法休眠之后
    private static void testSleep() {
        synchronized (lock) {
            try {
                System.out.println(Thread.currentThread().getName() + " 正在执行");

                Thread.sleep(1000);
                System.out.println(Thread.currentThread().getName() + " 休眠结束");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
